<?php

namespace App\Jobs;

use App\Models\Statistic;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use App\Services\Statistics\HardCount;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;

class RefreshStatisticJob implements ShouldQueue
{
	use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
	public $title;
	
    public function __construct($title)
    {
        $this->title = $title;
    }
    
    public function handle()
    {
    	$method = $this->title;
        $value = app(HardCount::class)->$method();
        Statistic::rewrite(Str::snake($this->title), $value);
    }
}
